import {animate} from './city/animate.js'

export function getElement(ele) {
    return document.getElementById(ele);
}
export function vendorsGetUrlParam (url) {
    let param={};
    let reg=/([^?&=#]+)=([^?&=#]+)/g;
    url.replace(reg,(a,b,c)=>{
        param[b]=c;
    });
    return param;
}

export function vendorsTrimStr(str) {
    return str.replace(/^\s+|\s+$/g, "");
}


export function toast(obj) {
    let defaultObj = {
        text: '',
    };
    obj = {...defaultObj, ...obj};
    let {id, text, oneflag} = obj;
    let toast = document.getElementById(id);
    if (!oneflag) {
        oneflag = "open";
    }
    if (oneflag == "open") {
        sessionStorage.setItem("oneflag", "close");
        toast.style.cssText = "display: block;";
        animate({
            ele: toast,
            target: {
                opacity: 1,
            },
            effect: ['Linear'],
            duration: 300,
        });
        toast.innerHTML = text;
        setTimeout(function () {
            toast.style.cssText = "display: none;";
            sessionStorage.setItem("oneflag", "open");
        }, 3000);
    }
}